/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aqu.controlador.Administrador;

import aqu.bean.generico.BeanGenerico;
import aqu.persistencia.Dao.Administracion.*;
import aqu.persistencia.entity.*;
import aqu.persistencia.utilidad.MessagesController;
import com.icesoft.faces.component.ext.RowSelectorEvent;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;

/**
 *
 * @author AQU
 */
@ManagedBean(name = "variablesController")
@ViewScoped
public class VariablesController extends BeanGenerico {

    private SegGlobal variable;
    private List<SegGlobal> lista;
    private SegGlobalManager SegGlobalManager = new SegGlobalManager();
    private boolean panelvisible;

    public VariablesController() {

        variable = new SegGlobal();
        lista = SegGlobalManager.getList();
    }

    public boolean isPanelvisible() {
        return panelvisible;
    }

    public void setPanelvisible(boolean panelvisible) {
        this.panelvisible = panelvisible;
    }

    public void llamarPanelvisible(ActionEvent event) {
        panelvisible = !panelvisible;
    }

    public List<SegGlobal> getLista() {
        lista = SegGlobalManager.getList();
        return lista;
    }

    public void setLista(List<SegGlobal> lista) {
        this.lista = lista;
    }

    public void nuevo(ActionEvent actionEvent) {
        variable = new SegGlobal();
    }

    public String eliminar() {
        try {
            SegGlobal variableTemp = (SegGlobal) (variable);
            if (SegGlobalManager.delete(variableTemp) == false) {
                llamarPanelvisible(null);

            }
        } catch (Exception e) {
            MessagesController.addInfo("Mensaje de error :", e.getMessage());
            llamarPanelvisible(null);
        }

        return "index";

    }

    public void insertar(ActionEvent actionEvent) {
        try {

            if (SegGlobalManager.create(variable) == false) {
                llamarPanelvisible(null);

            }
        } catch (Exception e) {
            MessagesController.addInfo("Mensaje de error :", e.getMessage());
            llamarPanelvisible(null);
        }

    }

    public void modificar(ActionEvent actionEvent) {
        try {
            if (SegGlobalManager.update(variable) == false) {
                llamarPanelvisible(null);

            }
        } catch (Exception e) {
            MessagesController.addInfo("Mensaje de error :", e.getMessage());
            llamarPanelvisible(null);
        }


    }

    public void rowSelectionListener(RowSelectorEvent event) {
        variable = lista.get(event.getRow());

    }

    public SegGlobalManager getSegGlobalManager() {
        return SegGlobalManager;
    }

    public void setSegGlobalManager(SegGlobalManager SegGlobalManager) {
        this.SegGlobalManager = SegGlobalManager;
    }

    public SegGlobal getVariable() {
        return variable;
    }

    public void setVariable(SegGlobal variable) {
        this.variable = variable;
    }

    
    
}
